﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace TestBrownser
{
    public class MapConfig
    {
        public List<MapItem> Maps = new List<MapItem>();
        public void Save()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(MapConfig));
            using (FileStream fs = new FileStream("config.xml", FileMode.Create))
            {
                serializer.Serialize(fs, this);
            }
        }
        public void Load()
        {
            MapConfig config;
            string filePath = "config.xml";
            XmlSerializer serializer = new XmlSerializer(typeof(MapConfig));
            if (!File.Exists(filePath))
                return;
            using (FileStream fs = new FileStream(filePath, FileMode.Open))
            {
                try
                {
                    config = serializer.Deserialize(fs) as MapConfig;
                    if (config != null)
                        this.Maps = config.Maps;

                }
                catch (Exception ex)
                {
                    throw;
                }
            }
        }

        internal MapItem GetProp(string propName)
        {
            foreach (var item in Maps)
            {
                if (item.PropName.Equals(propName, StringComparison.CurrentCultureIgnoreCase))
                {
                    return item;
                }
            }
            return new MapItem();
        }
    }
}
